package com.so.np2.algs;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


public class Random extends Strategy {

	HashMap<Integer, Integer> memoria = new HashMap<Integer, Integer>();
	List<Integer> emMemoria = new ArrayList<Integer>();

	public Random(int numFrames, List<Request> requests) {
		super(numFrames, requests);
	}

	public void run() {
		for (Request op : requests) {
			if (memoria.containsKey(op.value)) {
				hit++;
			} else {
				if (memoria.size() >= frameSize) {
					int removerAleatorio = new java.util.Random().nextInt(emMemoria.size());
					int removed = emMemoria.remove(removerAleatorio);
					memoria.remove(removed);
				}
				memoria.put(op.value, op.value);
				emMemoria.add(op.value);
			}
		}
	}

	public void reset() {
		memoria = new HashMap<Integer, Integer>();
		emMemoria = new ArrayList<Integer>();
		hit = 0;
	}

	public static String getName() {
		return "Random";
	}
}